home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / flxkey.exe / MAKEKEY3.PAS < prev    next >
Pascal/Delphi Source File  |  1993-02-21  |  6KB  |  151 lines

  1.  
  2. (**********************************************************************)
  3. (* Simple program to demonstrate how to use the FlxKey unit to create *)
  4. (* an encrypted "password" registration-key using one "embedded"      *)
  5. (* encryption-code and one user-entered "password" encryption-code.   *)
  6. (*                                                                    *)
  7. (* NOTE: Before you can compile this program, you must first          *)
  8. (*       compile and run the "RANDCODE.PAS" program to generate       *)
  9. (*       the two "random" encryption-code binary data files. Then     *)
  10. (*       run the "batch" file called "DAT2OBJ.BAT" to convert         *)
  11. (*       these two binary data files to "object" format files.        *)
  12. (**********************************************************************)
  13.  
  14. program Make_FlxKey_Demo3;
  15. uses
  16.   FlxKey;
  17.  
  18. type
  19.               (* 20 character string-pointer definition.              *)
  20.   post_20 = ^st_20;
  21.  
  22. var           (* This variable is used to check for errors returned   *)
  23.               (* by CreateFlxKey routine.                             *)
  24.   ErrorCode   : word;
  25.  
  26.               (* 1 encryption-code string-pointer.                    *)
  27.   Ecode1Ptr   : post_20;
  28.  
  29.               (* User "password" encryption-code.                     *)
  30.   st_Password : st_20;
  31.  
  32.               (* Full path/filename of the encrypted registration-key *)
  33.               (* file to be created.                                  *)
  34.   RegKeyName  : st_79;
  35.  
  36.               (* This variable is used to pass the user-data to the   *)
  37.               (* CreateFlxKey routine.                                *)
  38.   TempKeyRec : rc_Flx;
  39.  
  40.   {$F+}       (* Declare the following procedure as "FAR".            *)
  41.  
  42.               (* "Fake" procedure that contains first encryption-code *)
  43.               (* string.                                              *)
  44.   procedure Ecode1Data; external;
  45.   {$L ECODE1.OBJ}
  46.  
  47.   {$F-}       (* Turn off "FAR" declaration.                          *)
  48.  
  49.               (* Main program execution block.                        *)
  50. BEGIN
  51.               (* Initialize the encryption-code pointer to it's       *)
  52.               (* string data.                                         *)
  53.   Ecode1ptr := addr(Ecode1Data);
  54.  
  55.               (* Clear the temporary key-record variable.             *)
  56.   fillchar(TempKeyRec, sizeof(TempKeyRec), 0);
  57.  
  58.               (* Assign data to temporary key-record.                 *)
  59.   with TempKeyRec do
  60.     begin
  61.               (* 20 char space is available for first-name.           *)
  62.       FirstName := 'John';
  63.  
  64.               (* 30 char space is available for last-name.            *)
  65.       LastName  := 'Smith';
  66.  
  67.               (* 30 char space is available for Address1.             *)
  68.       Address1  := '1234 AnyPlace Road,';
  69.  
  70.               (* 30 char space is available for Address2.             *)
  71.       Address2  := 'BigCity BigPlace,';
  72.  
  73.               (* 30 char space is available for Address3.             *)
  74.       Address3  := 'BigCountry, BigZip';
  75.  
  76.               (* 20 char space is available for application-name.     *)
  77.       AppName   := 'Amazing Program';
  78.  
  79.               (* Version can be assigned any valid word data.         *)
  80.       Version   := 310;
  81.  
  82.               (* Serial can be assigned any valid longint data.       *)
  83.       Serial    := 1234567890;
  84.  
  85.               (* Date can be assigned any valid "packed" date/time.   *)
  86.               (* If a value of 0 is assigned to Date, CreateFlxKey    *)
  87.               (* routine will assign the current date/time to this    *)
  88.               (* variable in "packed" date/time format. Use TP's      *)
  89.               (* standard "PackTime" and "UnPackTime" routines to     *)
  90.               (* manipulate this data.                                *)
  91.       Date      := 0;
  92.  
  93.               (* Access level can be assigned a number from 0..65,535 *)
  94.       Access    := 1234;
  95.  
  96.       MiscData  := 'You can place what ever sort of data you like' +
  97.                    #13#10 + '                within this field, ' +
  98.                    'upto 254 bytes worth.'
  99.     end;
  100.  
  101.               (* Filename for the encrypted registration-key to be    *)
  102.               (* created.                                             *)
  103.   RegKeyName := 'DEMO3.KEY';
  104.  
  105.               (* Prompt for user "password" encryption-code string.   *)
  106.   writeln;
  107.   write('Enter Password : ');
  108.   readln(st_Password);
  109.  
  110.               (* Create encrypted registration-key using the data     *)
  111.               (* assigned to TempKeyRec.                              *)
  112.   CreateFlxKey(TempKeyRec, Ecode1Ptr^, st_Password, RegKeyName,
  113.                                                              ErrorCode);
  114.  
  115.               (* Move cursor down one line.                           *)
  116.   writeln;
  117.  
  118.               (* Check for errors.                                    *)
  119.   case (ErrorCode AND $FF) of
  120.      0 : writeln(' Sucessful key creation! No errors.');
  121.      1 : writeln(' Error! One or more encryption-codes is blank.');
  122.      2 : writeln(' Error! Filename for registration-key file is blank.');
  123.      3 : writeln(' HEAP allocation error. Unable to allocate 1024 ' +
  124.                  'buffer.');
  125.      4 : writeln(' BlocWrite error.');
  126.      5 : writeln(' BlockRead error.');
  127.      6 : writeln(' Date error. PC''s system date pre-dates ' +
  128.                  'registration-key date.');
  129.      7 : writeln(' Registration-key is corrupt.');
  130.  
  131.               (* I/O error!                                           *)
  132.     16 : begin
  133.            writeln(' I/O error = ', (ErrorCode shr 8));
  134.  
  135.               (* Standard Turbo Pascal error-codes. See TP manuals,   *)
  136.               (* as there are many types of errors to check for.      *)
  137.            case (ErrorCode shr 8) of
  138.                2 : writeln(' File not found.');
  139.                3 : writeln(' Path not found.');
  140.                4 : writeln(' Too many files open.');
  141.                5 : writeln(' File access denied.');
  142.              101 : writeln(' Disk write error.');
  143.              103 : writeln(' File not open');
  144.              150 : writeln(' Disk is write-protected')
  145.            end  (* case (ErrorCode shr 8) of                          *)
  146.          end
  147.   end         (* case (ErrorCode AND $FF) of                          *)
  148. END.
  149.  
  150.  
  151.